/*
 * @Author: samfeng
 * @Date: 2021-04-25 21:05:18
 * @LastEditTime: 2021-05-01 14:36:46
 * @LastEditors: Please set LastEditors
 * @Description: 点餐界面右边菜单类别展示
 * @FilePath: /first_flutter_app/lib/views/orderPage/rightCategoryList.dart
 */
import 'package:first_flutter_app/constant/dataInfo.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class CategoryList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Container(
        alignment: Alignment.centerLeft,
        // width: ScreenUtil().setWidth(150),
        height: ScreenUtil().setHeight(1900),
        child: _categoryWrap(),
      ),
    );
  }

  // 菜品类别
  List<Widget> _getCategoryList() {
    List<Widget> aList = categoryList.map((val) {
      return Container(
        height: ScreenUtil().setHeight(120),
        width: ScreenUtil().setWidth(150),
        child: ElevatedButton(
          onPressed: () {},
          style: ButtonStyle(
            // minimumSize: MaterialStateProperty.all(Size(120, 50)),
            backgroundColor: MaterialStateProperty.resolveWith((states) {
              //设置按下时的背景颜色
              if (states.contains(MaterialState.pressed)) {
                return Colors.blue[800];
              }
              //默认不使用背景颜色
              return Colors.white;
            }),
          ),
          child: Text(
            val,
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
            style: TextStyle(
              color: Colors.black45,
              fontWeight: FontWeight.w900,
              fontSize: ScreenUtil().setSp(50),
            ),
          ),
        ),
      );
    }).toList();
    return aList;
  }

  Widget _categoryWrap() {
    return SingleChildScrollView(
      child: Wrap(
        spacing: 10.0, // 主轴(水平)方向间距
        runSpacing: 25.0,
        children: this._getCategoryList(),
      ),
    );
  }

  Widget _categoryList() {
    return ListView.builder(
      scrollDirection: Axis.vertical,
      shrinkWrap: true,
      itemBuilder: (context, index) {
        return Container(
          // width: ScreenUtil().setWidth(900),
          // margin: EdgeInsets.all(ScreenUtil().setSp(50)),
          child: ElevatedButton(
            onPressed: () {},
            style: ButtonStyle(
              // minimumSize: MaterialStateProperty.all(
              //   Size(300, 150),
              // ),
              backgroundColor: MaterialStateProperty.resolveWith((states) {
                //设置按下时的背景颜色
                if (states.contains(MaterialState.pressed)) {
                  return Colors.blue[800];
                }
                //默认不使用背景颜色
                return Colors.white;
              }),
              textStyle: MaterialStateProperty.all(
                TextStyle(
                  fontSize: 70,
                ),
              ),
            ),
            child: Text(
              categoryList[index],
              style: TextStyle(
                color: Colors.black45,
                fontWeight: FontWeight.w900,
                // fontSize: ScreenUtil().setSp(100),
              ),
            ),
          ),
        );
      },
      itemCount: categoryList.length,
    );
  }
}
